import jdk.swing.interop.SwingInterOpUtils;

public class Hanuota {
    public static void move(char pos1, char pos2){
        System.out.print(pos1 + "->" + pos2 + " ");//移动盘子
    }
    public static void hanNuoTa(int n, char pos1, char pos2, char pos3) {
        if (n == 1){
            move(pos1, pos3);
        }else {
            hanNuoTa(n - 1, pos1, pos3, pos2);//通过中转位置pos3将n-1个全部移动到pos2上
            move(pos1, pos3);//回归后将最后一个移动到目标位置pos3上
            hanNuoTa(n - 1, pos2, pos1, pos3);//n-1个都在起始位置pos2上,通过中转位置pos1将n-1个全部移动到目标位置pos3上
        }
    }
    public static void main(String[] args) {
        hanNuoTa(1, 'A', 'B', 'C');
        System.out.println();
        hanNuoTa(2, 'A', 'B', 'C');
        System.out.println();
        hanNuoTa(3, 'A', 'B', 'C');
        System.out.println();
        hanNuoTa(5, 'A', 'B', 'C');
    }
}
